Ext.require([
    'Ext.form.*',
    'Ext.data.*',
    'Ext.layout.container.Column',
    'Ext.tab.TabPanel'
]);


/*!
 * Ext JS Library 3.3.1
 * Copyright(c) 2006-2010 Sencha Inc.
 * licensing@sencha.com
 * http://www.sencha.com/license
 */
Ext.onReady(function(){

    Ext.QuickTips.init();

    var bd = Ext.getBody();
    
	function getExtraParams(){
		var s = document.location.search.split('?');
		var a = {};
		if(s.length > 1){
			a = Ext.urlDecode(s[1]);
		}
		var b = {
				memberEmail: Ext.util.Cookies.get('memberEmail'),
				memberPassword: Ext.util.Cookies.get('memberPassword')

		};

		return Ext.merge(a,b);
		
	};

    var fp = Ext.create('Ext.form.FormPanel', {
        border:false,
        width: 350,
        fieldDefaults: {
            labelWidth: 75,
            msgTarget: 'side'
        },
        defaults: {
            anchor: '100%'
        },

        items: [{
            xtype: 'filefield',
            id: 'form-file',
            emptyText: 'Select an image',
            fieldLabel: 'Photo',
            name: 'photo-path',
            buttonText: '',
            buttonCfg: {
                iconCls: 'upload-icon'
            }
        }],
                   
        buttons: [{
            text: 'Salva',
            disabled: true,
            formBind: true,
			handler: function() {
				var form = this.up('form').getForm();
				if (form.isValid()) {
					form.submit({
						url: '../../../cattolica-web/item/photo/upload',
						params: getExtraParams(),
	                    submitEmptyText: false,
						success: function(form, action) {
						   document.location = 'list.html' + document.location.search;
						},
						failure: function(form, action) {
							Ext.Msg.alert('Failed', action.response.statusText);
						}
					});
				}
			}
        },{
            text: 'Cancel',
			handler: function() {
				history.back();
			}
        }]
    });

    fp.render(document.body);


});

